/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Golf_Manager;

/**
 *
 * @author Administrator
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
        
        javax.swing.JInternalFrame frm = new MemberMngFrame();
        this.jDesktopPane1.add(frm);
        frm.setVisible(true);
        
        try {
            frm.setMaximum(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuItem1 = new javax.swing.JMenuItem();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu2 = new javax.swing.JMenu();
        appCLose = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        memberMng = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        groupMake = new javax.swing.JMenuItem();
        groupSearch = new javax.swing.JMenuItem();

        jMenuItem1.setText("jMenuItem1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("골프 관리");
        setResizable(false);

        jDesktopPane1.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1024, Short.MAX_VALUE)
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 747, Short.MAX_VALUE)
        );

        getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER);

        jMenuBar1.setPreferredSize(new java.awt.Dimension(93, 30));

        jMenu2.setText("File");
        jMenu2.setMaximumSize(new java.awt.Dimension(50, 32767));
        jMenu2.setPreferredSize(new java.awt.Dimension(30, 50));

        appCLose.setText("종료");
        appCLose.setPreferredSize(new java.awt.Dimension(100, 22));
        appCLose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                appCLoseActionPerformed(evt);
            }
        });
        jMenu2.add(appCLose);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("관리");
        jMenu3.setMaximumSize(new java.awt.Dimension(50, 32767));
        jMenu3.setPreferredSize(new java.awt.Dimension(30, 50));

        memberMng.setText("회원관리");
        memberMng.setPreferredSize(new java.awt.Dimension(100, 22));
        memberMng.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memberMngActionPerformed(evt);
            }
        });
        jMenu3.add(memberMng);

        jMenuBar1.add(jMenu3);

        jMenu1.setText("도구");
        jMenu1.setMaximumSize(new java.awt.Dimension(50, 32767));
        jMenu1.setPreferredSize(new java.awt.Dimension(30, 50));

        groupMake.setText("조편성");
        groupMake.setPreferredSize(new java.awt.Dimension(100, 22));
        groupMake.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                groupMakeActionPerformed(evt);
            }
        });
        jMenu1.add(groupMake);

        groupSearch.setText("편성조 조회 및 점수입력");
        groupSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                groupSearchActionPerformed(evt);
            }
        });
        jMenu1.add(groupSearch);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void appCLoseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_appCLoseActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_appCLoseActionPerformed

    private void memberMngActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memberMngActionPerformed
        // TODO add your handling code here:
        javax.swing.JInternalFrame frm = searchFrame(jDesktopPane1, Golf_Manager.MemberMngFrame.class.getName());
        
        if(frm != null){
            this.jDesktopPane1.remove(frm);   
        } 
        
        frm = new MemberMngFrame();
        this.jDesktopPane1.add(frm);
        frm.setVisible(true);

        try {
            frm.setMaximum(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_memberMngActionPerformed

    private void groupMakeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupMakeActionPerformed
        // TODO add your handling code here:
        javax.swing.JInternalFrame frm = searchFrame(jDesktopPane1, Golf_Manager.GroupMakeFrame.class.getName());
        
        if(frm != null){
            this.jDesktopPane1.remove(frm);
        } 
        
        frm = new GroupMakeFrame();
        this.jDesktopPane1.add(frm);
        frm.setVisible(true);

        try {
            frm.setMaximum(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }//GEN-LAST:event_groupMakeActionPerformed

    private void groupSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupSearchActionPerformed
        // TODO add your handling code here:
        javax.swing.JInternalFrame groupSearchFrame = searchFrame(jDesktopPane1, Golf_Manager.GroupSearchFrame.class.getName());
        
        if(groupSearchFrame != null){
             groupSearchFrame.toFront();
        } else {
            groupSearchFrame = new GroupSearchFrame();
            this.jDesktopPane1.add(groupSearchFrame);
            groupSearchFrame.setVisible(true);
            
            try {
                groupSearchFrame.setMaximum(true);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        
    }//GEN-LAST:event_groupSearchActionPerformed

    private javax.swing.JInternalFrame searchFrame(javax.swing.JDesktopPane jDesktopPane, String className){
        
        for(javax.swing.JInternalFrame existFrm : jDesktopPane.getAllFrames()){
            if(existFrm.getClass().getName().equals(className)){
                return existFrm;
            }
        }
        return null;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem appCLose;
    private javax.swing.JMenuItem groupMake;
    private javax.swing.JMenuItem groupSearch;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem memberMng;
    // End of variables declaration//GEN-END:variables
}
